/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipasssystem.skipass;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author Mitya
 */
public abstract class AbstractSkiPass implements SkiPass {

    protected Date activationDate;
    protected Date expirationDate;
    protected SkiPassType type;
    private boolean blocked = false;

    @Override
    public void block() {

        if (!blocked) {
            blocked = true;
        }
    }

    @Override
    public void unblock() {

        if (blocked) {
            blocked = false;
        }
    }

    @Override
    public boolean isBlocked() {
        return blocked;
    }

    @Override
    public boolean isExpired() {
        Date currentDate = new Date(System.currentTimeMillis());
        return currentDate.getTime() > expirationDate.getTime();
    }

    protected boolean isWeekend() {
        Date currentDate = new Date(System.currentTimeMillis());
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(currentDate);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

        if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
            return true;
        }

        return false;
    }

    protected boolean isWorkday() {

        return !isWeekend();
    }

    public SkiPassType getSkiPassType() {

        return type;
    }

    @Override
    public String toString() {
        return type.toString() + " " + activationDate.toString() + " "
                + expirationDate.toString();
    }
}
